package com.feihong.yw189.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.feihong.yw189.R;
import com.feihong.yw189.model.PaiHangModel;
import com.holenzhou.pullrecyclerview.BaseRecyclerAdapter;
import com.holenzhou.pullrecyclerview.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;


/**
 * Created by PVer on 2018/1/5.
 */

public  class ShouYePaiHangAdapter extends BaseRecyclerAdapter<PaiHangModel.DataBean.PaihangTodayBean> {

    Activity mcontext;
    ArrayList<PaiHangModel.DataBean.PaihangTodayBean> paihangTodayBeans;

    public ShouYePaiHangAdapter(Context context, int layoutResId, List<PaiHangModel.DataBean.PaihangTodayBean> data) {
        super(context, layoutResId, data);
        mcontext= (Activity) context;
        paihangTodayBeans= (ArrayList<PaiHangModel.DataBean.PaihangTodayBean>) data;
    }


    @Override
    public void convert(BaseViewHolder holder, final PaiHangModel.DataBean.PaihangTodayBean item) {

        holder.setText(R.id.tv_dian,item.getAgent_name());
        holder.setText(R.id.tv_phonenumber,item.getMobile());
        holder.setText(R.id.tv_dan,item.getCount()+"单");


        CircleImageView imageView=holder.getView(R.id.iv_picloge);
        if(item.getUser_img() != null){
            Glide.with(mcontext).load(item.getUser_img()).apply(new RequestOptions().placeholder(R.mipmap.my_setting_photo)).into(imageView);
        }

         TextView textview=holder.getView(R.id.tv_paiming);
         ImageView  imageViewOne=holder.getView(R.id.iv_telphone);
        int position = holder.getLayoutPosition();
        if(position == 0){

            imageViewOne.setVisibility(View.VISIBLE);
            imageViewOne.setBackgroundResource(R.mipmap.diyi);
            textview.setVisibility(View.INVISIBLE);


            SpannableString spannabletext = new SpannableString(  item.getCount()+ "单");
            int text =item.getCount().length();
            ForegroundColorSpan ColorSpan = new ForegroundColorSpan(Color.RED);
            spannabletext.setSpan(ColorSpan, 0, text, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            spannabletext.setSpan(new RelativeSizeSpan(1.0f), 0, text, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 0.5f表示默认

            holder.setText(R.id.tv_dan,spannabletext);
        }else if(position == 1){

            imageViewOne.setVisibility(View.VISIBLE);
            imageViewOne.setBackgroundResource(R.mipmap.dier);
            textview.setVisibility(View.INVISIBLE);

            SpannableString spannabletext = new SpannableString(  item.getCount()+ "单");
            int text =item.getCount().length();
            ForegroundColorSpan ColorSpan = new ForegroundColorSpan(Color.RED);
            spannabletext.setSpan(ColorSpan, 0, text, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            spannabletext.setSpan(new RelativeSizeSpan(1.0f), 0, text, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 0.5f表示默认

            holder.setText(R.id.tv_dan,spannabletext);
        }else if(position == 2){

            imageViewOne.setVisibility(View.VISIBLE);
            imageViewOne.setBackgroundResource(R.mipmap.disan);
            textview.setVisibility(View.INVISIBLE);

            SpannableString spannabletext = new SpannableString(  item.getCount()+"单");
            int text =item.getCount().length();
            ForegroundColorSpan ColorSpan = new ForegroundColorSpan(Color.RED);
            spannabletext.setSpan(ColorSpan, 0, text, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
            spannabletext.setSpan(new RelativeSizeSpan(1.0f), 0, text, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 0.5f表示默认

            holder.setText(R.id.tv_dan,spannabletext);
        }else {
            textview.setVisibility(View.VISIBLE);
            for(int i=2;i < position ;i++){
                holder.setText(R.id.tv_paiming,String.valueOf(i+2));
            }
            imageViewOne.setVisibility(View.INVISIBLE);
        }
    }

}
